import java.awt.Color;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;

public class Pixel 
{
	private BufferedImage image;
	
	protected int width;
	protected int height;
	
	
	Pixel(File name)
	{
		try 
		{
			image = ImageIO.read(name);
			width = image.getWidth();
			height = image.getHeight();
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
	
	Pixel(Image in)
	{
		image = new BufferedImage(in.getWidth(null), in.getHeight(null), BufferedImage.TYPE_INT_RGB);	
		image.getGraphics().drawImage(in, 0, 0, null);

		width = image.getWidth();
		height = image.getHeight();
		
	}
	
	Pixel(int x, int y)
	{
		image = new BufferedImage(x, y, BufferedImage.TYPE_INT_RGB);	

		width = image.getWidth();
		height = image.getHeight();
		
	}
	
	
	
	public ImageIcon getImageIcon()
	{
		return new ImageIcon(image);
	}
		
	
	
	public Color getPixel(int x, int y)
	{
		return new Color(image.getRGB(x,y));
	}
	
	public void setPixel(int x, int y, Color c)
	{
		image.setRGB(x,y, c.getRGB());
	}
	
	public void safeAsPng(File out)
	{
		try
		{
			ImageIO.write( image, "png", out );
		} 
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
	
}
